<template>
	<div class="content">
		<div class="base">
			<Form inline class="fl">
				<Input type="text" placeholder="请输入会员ID" class="w200 m-r10" v-model.trim="uuid" />
				<Input type="text" placeholder="请输入接收人ID" class="w200 m-r10" v-model.trim="receiveUuid" />
				<Input type="text" placeholder="请输入交易ID" class="w200 m-r10" v-model.trim="tradeId" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getConditionQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累计转赠广告数量:
								<span class="blue" v-text="collectList.num == null ? 0 : collectList.num">0</span>
							</td>
							<td>累计实际到账数量:
								<span class="blue" v-text="collectList.actualNum == null ? 0 : collectList.actualNum">0</span>
							</td>
							<td>累计平台扣除手续费:
								<span class="blue" v-text="collectList.appFee == null ? 0 : collectList.appFee">0</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon>导出
		</Button>
		<Table stripe :columns="columns" :data="conditionQuery" ref="table"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery"></Page>
		
		<Modal v-model="modal" title="转赠会员详情" width='50%'>
			<Table height="200" class="m-t10" stripe :columns="columns1" :data='myUpList'></Table>
		</Modal>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dataValue: [], // 时间段值
				conditionQuery: [], // 条件查询的结果
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				uuid: '', // 会员 ID
				tradeId: '', // 转账 ID
				receiveUuid: '', // 接收人 ID
				modal: false,
				myUpList: [],
				collectList: [],
				columns: [{
						title: '会员ID',
						key: 'uuid',
						align: 'center',
						render: (h, params) => {
							return h(
								'div', {
									style: {
										cursor: 'pointer',
										color: '#2db7f5'
									},
									on: {
										click: () => {
											this.getUuid(params.row.uuid);
										}
									}
								},
								params.row.uuid
							)
						}
					},
					{
						title: '交易ID',
						key: 'tradeId',
						align: 'center'
					},
					{
						title: '接收会员ID',
						key: 'receiveUuid',
						align: 'center',
					},
					{
						title: '接收会员名称',
						key: 'receiveName',
						align: 'center'
					},
					{
						title: '转赠广告数量',
						key: 'num',
						align: 'center'
					},
					{
						title: '实际到账数量',
						key: 'actualNum',
						align: 'center'
					},
					{
						title: '平台扣除手续费',
						key: 'appFee',
						align: 'center'
					},
					{
						title: '平台手续费百分比',
						key: 'appRatio',
						align: 'center'
					},
					{
						title: '发送时间',
						key: 'sendTime',
						align: 'center',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.sendTime == null ? '#' : params.row.sendTime)
						}
					}
				],
				columns1: [
//					{
//						title: '个人ID',
//						align: 'center',
//						key: 'uuid'
//					},
					{
						title: '名称',
						align: 'center',
						key: 'nickName'
					},
					{
						title: '手机号码',
						align: 'center',
						key: 'phone',
						render: (h, params) => {
							return h('div', params.row.phone == null ? '#' : params.row.phone)
						}
					},
					{
						title: '会员类型',
						align: 'center',
						key: 'typeId',
						render: (h, params) => {
							if(params.row.typeId == 1) {
								return h('div', '普通会员');
							} else if(params.row.typeId == 2) {
								return h('div', '广告主')
							}
						}
					},
					{
						title: '注册时间',
						align: 'center',
						key: 'createTime',
						sortable: true
					}
				]
			}
		},
		mounted() {
			this.$Message.config({ // 配置弹窗的位置
				top: 250
			});
			this.getQuery(); // 发送列表查询
			this.getCollect(); // 转赠列表的汇总
		},
		methods: {
			getTime(daterange) {
				this.dataValue = daterange
			},
			exportData() { // 导出
				this.$refs.table.exportCsv({
					filename: '转赠列表'
				})
			},
			getQuery() { // 发送列表查询
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: '', // 会员 ID
					tradeId: '', // 转账 ID
					receiveUuid: '', // 接收人 ID
					startTime: '2000-12-30 00:00:00', // 起始日期
					endTime: '2200-12-30 00:00:00' // 结束日期
				})
				this.axios.post('send/sendlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.conditionQuery = res.data.data.sendListVoList;
						this.info = res.data.data.total;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			cuctGetQuery(page) { // 发送列表分页查询
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: '', // 会员 ID
					tradeId: '', // 转账 ID
					receiveUuid: '', // 接收人 ID
					startTime: '2000-12-30 00:00:00', // 起始日期
					endTime: '2200-12-30 00:00:00' // 结束日期
				})
				this.axios.post('send/sendlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.conditionQuery = res.data.data.sendListVoList;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			getConditionQuery() { // 发送列表条件查询
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid, // 会员 ID
					tradeId: this.tradeId, // 转账 ID
					receiveUuid: this.receiveUuid, // 接收人 ID
					startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0], // 起始日期
					endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1] // 结束日期
				})
				this.axios.post('send/sendlist', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008 || res.data.code == 4004) {
						this.conditionQuery = res.data.data.sendListVoList;
						this.info = res.data.data.total;
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			getUuid(id) {
				let token = localStorage.getItem('mytoken')
				this.modal = true;
				this.axios.get('send/personage/' + id,{
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.myUpList = res.data.data.pMemberVo;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			getCollect() { // 转赠列表的汇总
				let token = localStorage.getItem('mytoken')
				this.axios.get('send/collect/',{
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.collectList = res.data.data;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>